package com.hxx.day7;

import org.junit.Test;

import java.util.TreeSet;

public class TestDemo5 {
    @Test
    public void test02(){
        TreeSet treeSet = new TreeSet((x,y)->((Person1)y).getId()-((Person1)x).getId());
        treeSet.add(new Person1(3,"zhangsan",18));
        treeSet.add(new Person1(2,"lisi",20));
        treeSet.add(new Person1(10,"wangwu",15));
        System.out.println(treeSet);
    }
}
class Person1 {
    private int id;
    private String name;
    private int age;

    public Person1() {
    }

    public Person1(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}